<style>
	body{
		background-color: #ccffcc;
	}
</style>
<script>
	(function () {

    })()
</script>

<div >
	<h1>日志记录列表页面</h1>
	<div style="border: 1px solid red;width: 600px;">
		<form id="importExcel" action="#" enctype="multipart/form-data">
			<input type="file" name="file">
			<a href="javascript:importExcel();" class="btn green"> 导入Excel测试 </a>
		</form>
	</div>
	<form id="searchForm">
	<table border=1>

		<tr>
			<td><button type="button" onclick="setLog()">设置</button></td>
			<td><button  type="button" onclick="add()">添加</button> </td>
			<td>
				<button type="button" onclick="delMore()">批量删除</button>
				<button id="exportSysLog"  type="button" >导出日志</button>
			</td>
			<td>日志内容：<input id="content" name="content" #if($sysLog.content) value="${sysLog.content}" #end /></td>
			<td>起始时间<input id="startdate" name="startdate" #if($sysLog.startdate) value="${sysLog.startdate}" #end /></td>
			<td>终止时间<input id="enddate" name="enddate" #if($sysLog.enddate) value="${sysLog.enddate}" #end /></td>
			<td>类型
				<select name="type" id="type">
					<option value="">全部</option>
					<option value="0" #if($sysLog.type==0) selected="selected" #end >增加数据</option>
					<option value="1" #if($sysLog.type==1) selected="selected" #end >修改数据</option>
					<option value="2" #if($sysLog.type==2) selected="selected" #end >删除数据</option>
					<option value="3" #if($sysLog.type==3) selected="selected" #end >登录系统</option>
					<option value="5" #if($sysLog.type==5) selected="selected" #end >查询数据</option>
					<option value="9" #if($sysLog.type==3) selected="selected" #end >系统异常</option>
					<option value="4" #if($sysLog.type==3) selected="selected" #end >其他</option>
				</select>
			</td>
			<td>
				&nbsp;&nbsp;<button   type="button" onclick="searchSysLog()">查询</button>
				<button  type="button" onclick="reSetFrom()">重置</button>
			</td>
		</tr>

		<tr>
			<td colspan="8">
				页数：<input id="page" name="page" placeholder="1" value="${page}" />
				条数：
				<select name="row" id="row">
					<option value="2" #if($row == 1 ) selected="selected" #end >2</option>
					<option value="5" #if($row == 5 ) selected="selected" #end >5</option>
					<option value="10" #if($row == 10 ) selected="selected" #end>10</option>
				</select>
				<button  type="button" onclick="testpage()">跳转</button>
			</td>
		</tr>


		<tr>
			<td align="center"><input id="selectall" type="checkbox" /></td>
			<td>序号</td>
			<td>内容</td>
			<td>类型</td>
			<td>操作模块</td>
			<td>操作人</td>
			<td>时间</td>
			<td>操作</td>
		</tr>
		#if( $sysLogList )
			#set ($rowNum=0)
		#foreach($res in $sysLogList)
			#set($rowNum=$rowNum+1)
		<tr>
			<td align="center"><input id="${res.id}" name="selectsingle" style="width:20px" type="checkbox" /></td>
			<td>${rowNum}</td>
			<td>
				#if($res.content.length()>10)
				#set($res.content = $res.content.substring(0,10))
				${res.content}
				#else
				${res.content}
				#end
			</td>
			<td>
				#if($res.type == 0)
					<span>增加数据</span>
				#elseif($res.type == 1)
					<span>修改数据</span>
				#elseif($res.type == 2)
					<span>删除数据</span>
				#elseif($res.type == 3)
					<span>登录系统</span>
				#elseif($res.type == 4)
					<span>其他</span>
				#elseif($res.type == 9)
					<span>系统异常</span>
				#elseif($res.type == 5)
					<span>查询数据</span>
				#else
					<span>未知类型</span>
				#end
			</td>
			<td>
				#if( $res.optunit )
					${res.optunit}
				#else

				#end
			</td>
			<td>${res.optusername}</td>
			<td>${res.createtime}</td>
			<td>
				<a style="color: blue;cursor: pointer;" onclick="jump('${res.id}')">查看</a>
				/
				<a style="color: blue;cursor: pointer;" onclick="update('${res.id}')">修改</a>
				/
				<a style="color: blue;cursor: pointer;" onclick="del('${res.id}')">删除</a>
			</td>
		</tr>
		#end
		#else
		<div></div>
		#end



	</table>
	</form>




</div>

<script type="text/javascript">

    function add(){//跳转到 添加页面
        location.href = "${path}/log/jump?optType=add";
    }

    function update(id){//跳转到 修改页面
        location.href = "${path}/log/jump?optType=update&id="+id;
    }

    function delMore(){
        var id  = "";
        var children = document.getElementsByName("selectsingle");
        if(children){
            for(var i = 0; i<children.length ;i++){
                if(children[i].checked){//选中了,
                    id = id + children[i].getAttribute("id") +",";
                }
            }
        }
        if(id==""){
            alert("请选择要删除的数据");
            return;
        }
        id = id.substring(0,(id.length-1));
        del(id);
    }

    function del(id){//删除操作
        var url = "${path}/log/delete?id="+id;
        $.ajax({
            url:url,
            Type:"POST",
            data:{},
            dataType:"json",
            success:function(data){
                console.log(data.message);
                alert("删除成功！");
                location.href= "${path}/log/index";
            },
            error:function(data){
                console.log("保存失败！");
                console.log(data.message);
                alert("保存失败！");
            }
        });

    }

    function jump(id){//跳转到 查看yemian
        console.log(id);
        location.href = "${path}/log/jump?optType=detail&id="+id;
        /* $.ajax({
            url:"${path}/SysLog/jump";
            data:{"id",id},
            dataType:"json",
        }) */
    }


    function searchSysLog(){
        var data = $("#searchForm").serialize();
        location.href = "${path}/log/index?"+data;
    }

    function testpage(){
        var page = $("#page").val();
        var row = $("#row").val();
        location.href = "${path}/log/index?row="+row+"&page="+page;
    }

    $("#exportSysLog").on("click",function () {
        if(confirm("是否确定要导出数据吗？")){
            //防止多次点击
            $("#exportSysLog").attr("disabled","disabled");
            location.href = "${path}/log/export";
        }
    });




    function importExcel(){
        var formData = new FormData($( "#importExcel" )[0]);
        var ajaxUrl = "${path}/log/import";
        //alert(ajaxUrl);
        //$('#uploadPic').serialize() 无法序列化二进制文件，这里采用formData上传
        //需要浏览器支持：Chrome 7+、Firefox 4+、IE 10+、Opera 12+、Safari 5+。
        $.ajax({
            type: "POST",
            //dataType: "text",
            url: ajaxUrl,
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                console.log(data)
            },
            error: function(data) {
                console.log("出错：")
                console.log(data)
                console.log(data.responseText)
            }
        });
        return false;
    }

    //重置
    function reSetFrom(){
        var hrefsrc = location.href;
        hrefsrc = hrefsrc.substring(0,hrefsrc.indexOf("?"));
        location.href = hrefsrc;
    }


function setLog() {
	alert("设置个什？");
}




    //实现全选和取消全选
    $("#selectall").on("click",function () {
        //jquery 方式 有时候 会不起左右，这里用JavaScript方式
        //var isSelected = $("#selectall").is(':checked');
        var children = document.getElementsByName("selectsingle");
        if(children){
            for(var i=0;i<children.length;i++){
                if(document.getElementById("selectall").checked){//全选
                    children[i].checked=true;
                }else{
                    children[i].checked=false;
                }
            }
        }

    });


    //单个点击的时候，实现全选和取消全选
    $("[name='selectsingle']").on("click",function () {
        if(this.checked){//选中了
            //判断其他项是不是 也选中了，
            if(isCheckAll('selectsingle')){//加上这个刚好全选
                document.getElementById("selectall").checked=true;
            }
        }else{//该项点击的是 取消选中，所以不管什么 selectall 都为不全选
            document.getElementById("selectall").checked=false;
        }
    });
    //判断所有的 checkbox是否全选
    function isCheckAll(name) {
        var children = document.getElementsByName(name);
        var flag = true;
        if(children){
            for(var i=0;i<children.length;i++){
                if(!children[i].checked){//有 没选中的
                    flag = false;
                }
            }
        }
        return flag;
    }

</script>